<template>
    <transition name="slide-right">
        <v-touch v-on:swiperight="" class="content-gray">
            <div class="identity-title">
                <span class="mui-icon mui-icon-back" @click="backRoute()"></span>
                <span>{{ $t('m.my.identity.listTitle') }}</span>
                <span></span>
            </div>
            <div class="information-content">
                <div>
                    <div class="photo-title">{{ $t('m.my.identity.prompt[0]') }}</div>
                    <div class="photo-img"><img :src="walletCreate.avatar" alt=""></div>
                </div>
                <div>
                    <div>{{ $t('m.my.identity.prompt[1]') }}</div>
                    <div class="username">{{ walletCreate.name }}</div>
                </div>
                <div>
                    <!--TODO-->
                    <div>{{ $t('m.my.identity.prompt[2]') }}</div>
                    <div class="userid">{{ uuid }}</div>
                </div>
            </div>
            <!--TODO-->
            <!--<div class="my-mail">-->
                <!--<div>邮箱</div>-->
                <!--<div>订阅</div>-->
            <!--</div>-->
            <div class="identity-operation">
                <div @click="backupPre()">{{ $t('m.my.identity.prompt[3]') }}</div>
                <div @click="exitPre()">{{ $t('m.my.identity.prompt[4]') }}</div>
            </div>
            <Prompt></Prompt>
        </v-touch>
    </transition>
</template>
<script>
    /* eslint-disable */
    import {myAlert} from "@/assets/js/h5plus/nativeUI";
    import {detail} from '@/assets/js/etherjs/wallet'
    import {AESDecrypt} from '@/assets/js/utils/crypto'

    export default {
        name: 'my_index',
        mounted() {
            if (typeof plus != "undefined") {
                this.uuid = plus.device.uuid;
            }
        },
        data() {
            return {
                type: "", // 备份身份：backup;退出身份：walletDel,
                uuid: "",
            }
        },
        watch: {
            // 监听密码框-确认按钮
            prompt(v) {
                if (v.isConfirm) {
                    if (v.complete == 'backup') {
                        // computed计算到的变化，不及时？
                        this.backupDo(v.value);
                    }
                    if (v.complete == 'exit') {
                        // computed计算到的变化，不及时？
                        this.exitDo(v.value);
                    }
                }
            }
        },
        methods: {
            backupPre: function () {
                if(this.walletCreate.mnemonic == ""){
                    myAlert({
                        msg: this.$t('m.my.identity.prompt[5]'),
                        button: this.$t('m.my.identity.prompt[6]')
                    });
                    return
                }
                this.aPrompt({
                    show: true,
                    title: this.$t('m.my.identity.prompt[7]'),
                    cancel: this.$t('m.my.identity.prompt[8]'),
                    confirm: this.$t('m.my.identity.prompt[6]'),
                    type: "password",
                    placeholder: this.$t('m.my.identity.prompt[7]'),
                    complete: "backup"
                })
            },
            backupDo: function (pwd) {
                // 生成助记词
                let mnemonic = AESDecrypt({
                    pwd: pwd,
                    msg: this.walletCreate.mnemonic
                });
                if (mnemonic == '') {
                    myAlert({
                        msg: this.$t('m.my.identity.prompt[9]'),
                        button: this.$t('m.my.identity.prompt[6]')
                    });
                } else {
                    this.aWalletDecode({
                        mnemonic: mnemonic
                    });
                    this.changeRoute("/wallet/backup/mnemonic")
                }
            },
            exitPre: function () {
                let that = this;
                myAlert({
                    title: this.$t('m.my.identity.prompt[4]'),
                    msg: this.$t('m.my.identity.prompt[10]'),
                    button: this.$t('m.my.identity.prompt[6]'),
                    callBack: function () {
                        that.aPrompt({
                            show: true,
                            title: that.$t('m.my.identity.prompt[7]'),
                            cancel: that.$t('m.my.identity.prompt[8]'),
                            confirm: that.$t('m.my.identity.prompt[6]'),
                            type: "password",
                            placeholder: that.$t('m.my.identity.prompt[7]'),
                            complete: "exit"
                        })
                    }
                });
            },
            exitDo: function (pwd) {
                let pKey = AESDecrypt({
                    pwd: pwd,
                    msg: this.walletCreate.pKey
                });
                if (pKey == '') {
                    myAlert({
                        msg: this.$t('m.my.identity.prompt[9]'),
                        button: this.$t('m.my.identity.prompt[6]')
                    });
                } else {
                    // localStorage.removeItem('walletActive');
                    // localStorage.removeItem('walletCreate');
                    // localStorage.removeItem('wallets');
                    // localStorage.removeItem('contract');
                    localStorage.clear();
                    this.changeRoute('/');
                }
            },
        }
    }
</script>
<style scoped>
    @import '../../assets/css/myIdentity.css';
</style>